/*
 * @Author: zhangyun
 * @Date: 2021-04-26 16:56:36
 * @LastEditors: zhangyun
 * @LastEditTime: 2021-04-27 14:52:22
 * @Desc: 
 */
import axios from 'axios'

axios.create({
  timeout: 5000
})

axios.interceptors.request.use(
  (config:any) => {
    if (config.url?.includes('login')) return config
    if(localStorage.getItem('token')) {
      config.headers['authorization'] = 'authorization' + localStorage.getItem('token')
      return config
    }
    
  },
  error => {
    return Promise.reject(error);
  })

axios.interceptors.response.use(
  response => {
    if (response.status == 200) {
      return Promise.resolve(response.data);
    } else {
      return Promise.reject(response);
    }
  },
  error => {
    alert(`异常请求：${JSON.stringify(error.message)}`)
  }
)

export default axios